﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainDriver.DomainModeling.DomainObjects;
using AutomotivePricingModel.ValueObjects.YearlyFinancialAssessments;

namespace AutomotivePricingModel.Vehicles
{
    // LATER: Should be unique on m_ParentProductionModel, m_ModelYear, and hash of m_OptionsConfiguration
    public partial class Vehicle : KeyedDomainObjectBase<Guid, Vehicle>
    {
        private Nullable<Guid> m_ParentProductionModel;
        private Nullable<int> m_ModelYear;
        private OptionsConfiguration m_OptionsConfiguration;
        private Nullable<Guid> m_PriceHistoryId;
        private YearlyFinancialAssessment m_PriceHistory;

        public Vehicle()
        {
            m_Key = Guid.NewGuid();
            m_ParentProductionModel = null;
            m_ModelYear = null;
            m_OptionsConfiguration = new OptionsConfiguration();
            m_PriceHistory = new YearlyFinancialAssessment();
            m_PriceHistoryId = m_PriceHistory.Key;
        }

        public Nullable<Guid> ParentProductionModel
        {
            get { return m_ParentProductionModel; }
            set { m_ParentProductionModel = value; }
        }

        public Nullable<int> ModelYear
        {
            get { return m_ModelYear; }
            set { m_ModelYear = value; }
        }

        public OptionsConfiguration OptionsConfiguration
        {
            get { return m_OptionsConfiguration; }
        }

        public YearlyFinancialAssessment PriceHistory
        {
            get { return m_PriceHistory; }
        }

        #region DomainObject Methods

        public override Vehicle Copy()
        {
            Vehicle copy = new Vehicle();
            CopyTo(copy);
            return copy;
        }

        public override void CopyTo(Vehicle otherObject)
        {
            if (otherObject.m_Key != m_Key)
            { otherObject.m_Key = m_Key; }
            if (otherObject.m_ParentProductionModel != m_ParentProductionModel)
            { otherObject.m_ParentProductionModel = m_ParentProductionModel; }
            if (otherObject.m_ModelYear != m_ModelYear)
            { otherObject.m_ModelYear = m_ModelYear; }
            if (!m_OptionsConfiguration.Equals(otherObject.m_OptionsConfiguration))
            { otherObject.m_OptionsConfiguration = m_OptionsConfiguration.Copy(); }
            if (!otherObject.m_PriceHistoryId.Equals(m_PriceHistoryId))
            { otherObject.m_PriceHistoryId = m_PriceHistoryId; }
            if (m_PriceHistory == null)
            { otherObject.m_PriceHistory = null; }
            else if (!m_PriceHistory.Equals(otherObject.m_PriceHistory))
            { otherObject.m_PriceHistory = m_PriceHistory.Copy(); }
        }

        public override bool Equals(Vehicle otherObject)
        {
            if (otherObject.m_Key != m_Key)
            { return false; }
            if (otherObject.m_ParentProductionModel != m_ParentProductionModel)
            { return false; }
            if (otherObject.m_ModelYear != m_ModelYear)
            { return false; }
            if (!otherObject.m_OptionsConfiguration.Equals(m_OptionsConfiguration))
            { return false; }
            if (!otherObject.m_PriceHistoryId.Equals(m_PriceHistoryId))
            { return false; }
            if (m_PriceHistory == null)
            { return (otherObject.m_PriceHistory == null); }
            else if (!m_PriceHistory.Equals(otherObject.m_PriceHistory))
            { return false; }
            return true;
        }

        #endregion
    }
}